package com.coolrui.domain.prometheus;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * Prometheus自定义业务监控-用户服务
 */
@Component
@Getter
@Slf4j
public class UserServiceMetrics {
    private static final Random random = new Random();
    private static final String serviceName = "UserService";

    @Autowired
    private CustomMetricsService metricsService;

    // 记录监控QPS指标
    public void recordRequest(String methodName) {
        String uri = serviceName+"."+methodName;
        // 记录请求次数
        metricsService.recordRequest(uri, serviceName);
    }

    // 记录监控金额指标
    public void recordAmount(String methodName, long amount) {
        String uri = serviceName+"."+methodName;
        // 记录金额，单位：元
        metricsService.recordAmount(uri, serviceName, amount);
    }
}


